home *** CD-ROM | disk | FTP | other *** search
- // Animate Value block; Animation library
- // This block animates a value from a value connector.
- // Copyright © 1992-1994 by Imagine That,Inc.
- // All Rights Reserved.
-
- // modified
- // 12/17/92 JSL added theObj to else clause
- // 1/27/94 DJK removed time delay on displaying value -> added check to see if current value was == to last
- // 4/25/94 DJK changed initialization to hide if animation not on and reset values to 0 if animation is on
-
- integer theObj, thePattern, useHObject, alreadyShown;
- real lastHeight;
- integer oldTicks;
- real oldvalue;
-
- procedure GetPatternAndColor()
- {
- if (Solid) thePattern = 1;
- else if (Dark) thePattern = 3;
- else if (Medium) thePattern = 4;
- else thePattern = 23;
- if (Black) AnimationColor(theObj, 0, 0, 0, thePattern);
- else if (White) AnimationColor(theObj, 0, 0, 65535, thePattern);
- else if (Red) AnimationColor(theObj, 0, 65535, 65535, thePattern);
- else if (Orange) AnimationColor(theObj, 5461, 65535, 65535, thePattern);
- else if (Yellow) AnimationColor(theObj, 10923, 65535, 65535, thePattern);
- else if (Green) AnimationColor(theObj, 21845, 65535, 65535, thePattern);
- else if (Blue) AnimationColor(theObj, 43691, 65535, 65535, thePattern);
- else if (Purple) AnimationColor(theObj, 54614, 65535, 65535, thePattern);
- }
-
- // This message occurs for each step in the simulation.
- on simulate
- {
- real theHeight;
- integer newTicks;
-
- Con1Out=Con1In; //Pass data through
-
- if (showValue)
- {
- if ( !useHObject) // set it to internal
- theObj = 2;
-
- newTicks = TickCount();
- // if (newTicks-oldTicks > 30)
- if(con1In != oldValue)
- {
- // oldTicks = newTicks;
- oldValue = Con1In;
- GetPatternAndColor();
- AnimationText(theObj, Con1in);
- AnimationShow(theObj);
- }
- }
- else if (animateLevel)
- {
- if ( !useHObject) // set it to internal
- theObj = 1;
-
- theHeight = (Con1In - Min)/(Max - Min);
- if (theHeight != lastHeight)
- {
- GetPatternAndColor();
- AnimationLevel(theObj, theHeight);
- AnimationShow(theObj);
- lastHeight = theHeight;
- }
- }
- else //Selected AnimateFlash
- {
- if (Con1In >= Thresh)
- {
- if (! useHObject) // set it to internal
- {
- if (FlashText)
- theObj = 2;
- else
- theObj = 1;
- }
-
- if (playMovie)
- {
- while (waitDone && ! AnimationMovieFinish(theObj))
- ; // wait here to replay
-
- if (AnimationMovieFinish(theObj)) // if it's done, start again
- AnimationMovie(theObj, movieName, speed, TRUE, TRUE);
- }
- else if (! alreadyShown) // not up yet - prevent flashing
- {
- GetPatternAndColor();
-
- if (FlashBox)
- AnimationRectangle(theObj);
- else if (FlashCircle)
- AnimationOval(theObj);
- else if (FlashText)
- AnimationText(theObj, TextToFlash);
- else if (ShowPicture)
- AnimationPicture(theObj, pictureName, TRUE);
-
- AnimationShow(theObj);
- alreadyShown = TRUE;
- }
- }
- else
- {
- if (! useHObject) // set it to internal 12/17/92 JSL
- {
- if (FlashText)
- theObj = 2;
- else
- theObj = 1;
- }
-
- AnimationHide(theObj, FALSE);
- alreadyShown = FALSE;
- }
- }
- }
-
- // see if the user has entered an H-Block animation object
- on checkData
- {
- if (noValue(objNum))
- useHObject = FALSE; // blank means use our internal icon objects
- else
- {
- theObj = -objnum; // negate it for H-Block animation object
- useHObject = TRUE;
- }
-
- if (Max<=Min)
- {
- UserError("The maximum must be greater than the minimum to use animate \
- level in Animate Value block "+myBlockNumber());
- Abort;
- }
- }
-
-
- // Initialize any simulation variables.
- on initsim
- {
- if(useHObject == TRUE)
- {
- if(animationOn)
- {
- if(showValue)
- {
- AnimationText(theObj, "");
- animationShow(theObj);
- }
- else if(animateLevel)
- {
- GetPatternAndColor();
- AnimationLevel(theObj, 0);
- AnimationShow(theObj);
- }
- }
- else
- {
- AnimationText(theObj, "");
- animationHide(theObj, FALSE);
- }
- }
- else
- {
- AnimationHide(1, FALSE); // JSL hide all, for animation off, and unused types
- AnimationHide(2, FALSE);
- }
-
- lastHeight = -1000; // JSL so that we don't save it from last run
- alreadyShown = FALSE;
- oldTicks = 0;
- }
-
- // Initialize any block variables.
- on createBlock
- {
- Thresh = 0.5;
- FlashBox = TRUE;
- Black = TRUE;
- Solid = TRUE;
- TextToFlash = "Some text";
- Max = 1.0;
- Min = -1.0;
- speed = 1.0;
- oldvalue = 0.0;
- }